package cn.kicsy.www.anonymous_bbs.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 用于生成OpenAPI Markdown文档的命令行工具
 */
@Component
public class OpenApiMarkdownGenerator implements CommandLineRunner {

    @Autowired
    private OpenApiToMarkdownConverter converter;

    @Override
    public void run(String... args) throws Exception {
        if (args.length > 0 && "generate-docs".equals(args[0])) {
            System.out.println("开始生成OpenAPI Markdown文档...");
            
            // 等待应用启动完成
            Thread.sleep(5000);
            
            // 设置文件路径
            String jsonFilePath = "target/openapi.json";
            String markdownFilePath = "target/api-documentation.md";
            
            // 转换文档
            converter.convertJsonToMarkdown(jsonFilePath, markdownFilePath);
            
            System.out.println("OpenAPI Markdown文档生成完成!");
            
            // 退出应用
            System.exit(0);
        }
    }
}